# Copyright 2006 Michael Gorsuch <michael@styledbits.com>

# This file is part of GrabTheMic <http://www.grabthemic.org>.

# GrabTheMic is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.

#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.

#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA


# Filters added to this controller will be run for all controllers in the application.
# Likewise, all the methods added will be available for all controllers.


class ApplicationController < ActionController::Base

  include ExceptionNotifiable 
  
  def logged_in?
    if session[:user_id]
      true
    else
      false
    end
  end
  
  def set_user
    if logged_in?
      @user = get_user
    else
      @user = nil
    end
  end
  
  def get_user
    User.find(session[:user_id])  
  end
    
  def authorize
    if !session[:user_id]
      redirect_to(:controller => "user", :action => "login", :return_to => request.request_uri)
    end
  end
  
  def admin_authorize
    if !session[:user_id] or !User.find(session[:user_id]).admin?
      redirect_to :controller => "/user", :action => "login", :return_to => request.request_uri
    end
  end
  
  def test
    render :text => @request.inspect
  end
  
end
